﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace InfiniTec
{
    public static class StringExtension
	{
		public static bool MatchesWildcardPattern(this string input, string pattern)
		{
			if (string.IsNullOrEmpty(pattern)) throw new ArgumentNullException("pattern");

			input = input ?? string.Empty;

			string regex = "^" + Regex.Escape(pattern).Replace("\\*", ".*").Replace("\\?", ".") + "$";

			return Regex.IsMatch(input, regex);
		}
		public static string Format(this string input, params object[] args)
		{
			if (string.IsNullOrEmpty(input)) throw new ArgumentNullException("input");
			return string.Format(input, args);
		}

		public static string Format(this string input, object arg)
		{
			if (string.IsNullOrEmpty(input)) throw new ArgumentNullException("input");
			return string.Format(input, arg);
		}

		public static string Format(this string input, object arg1, object arg2)
		{
			if (string.IsNullOrEmpty(input)) throw new ArgumentNullException("input");
			return string.Format(input, arg1, arg2);
		}
		public static string Format(this string input, object arg1, object arg2, object arg3)
		{
			if (string.IsNullOrEmpty(input)) throw new ArgumentNullException("input");
			return string.Format(input, arg1, arg2, arg3);
		}

        public static bool IsNullOrEmpty(this string input)
        {
            return string.IsNullOrEmpty(input);
        }

        public static bool IsNotNullOrEmpty(this string input)
        {
            return !string.IsNullOrEmpty(input);
        }
        
        public static string Join(this IEnumerable<string> input, string separator)
        {
            return string.Join(separator, input.ToArray());
        }
	}
}
